package com.duothread;

import java.util.Date;

public class Demo3 {
    public static void main(String[] args) {
        // 创建任务类对象
        SleepTask sleepTask = new SleepTask();
        // 创建线程类对象
        Thread thread1 = new Thread(sleepTask, "线程1");
        // 启动线程
        thread1.start();
    }
}

// 任务类
class SleepTask implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "：" + i + " 时间：" + new Date());
        }
        // 让线程休眠1秒(单位是毫秒)
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}